<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑新入院长者准备表</title>
	<#include "/common/resource.ftl">
    <link rel="stylesheet" href="${params.contextPath}/static/plug/layui/css/layui.css">
    <link rel="stylesheet" href="${params.contextPath}/static/css/jquery-ui.min.css">
    <script src="${params.contextPath}/static/js/jquery-ui.min.js"></script>
    <script type="text/javascript">
		$(function () {
            <#if (params.tag)??>
            $( "#elderName").autocomplete({
                source: function(request, response) {
                    $.ajax({
                        url: "${params.contextPath}/web/elder/listAll.json",
                        dataType: "json",
                        data: {
                            name: $("#elderName").val().trim()
                        },
                        success: function(data) {
                            response($.map(data.data, function(item) {
                                return {
                                    value: item.name,
                                    id: item.id
                                }
                            }));
                        }
                    });

                },
                select: function(e, ui) {
                    $("[name='elderId']").val(ui.item.id);
                },
                maxLength: 2
            });
            <#else>
            LocalStorage.registHandler("elder_handler_select", function (data) {
                $('input[name="elderId"]').val(data.id);
                $('input[name="elderName"]').val(data.name);
            });
            </#if>
			<#if (params.id)??>
				$.ajaxRequest({
					url: '${params.contextPath}/web/newElderPreparation/query.json',
					data: {id: "${params.id}"},
					success: function (data) {
						if (!data.success) {
							$.message(data.message);
							return;
						}
						var record = data.data;
						console.log(record);
						for (var key in record) {
                            if (key == 'itemPreparation') {
                                var itemPreparation = record.itemPreparation;
                                var itemPreparationArray = itemPreparation.split(",");
                                var itemPreparationAll = $("input[name='itemPreparation']");
                                for(var i=0; i<itemPreparationArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(itemPreparationAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(itemPreparationArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'checkHygiene') {
                                var checkHygiene = record.checkHygiene;
                                var checkHygieneArray = checkHygiene.split(",");
                                var checkHygieneAll = $("input[name='checkHygiene']");
                                for(var i=0; i<checkHygieneArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(checkHygieneAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(checkHygieneArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'notebook') {
                                var notebook = record.notebook;
                                var notebookArray = notebook.split(",");
                                var notebookAll = $("input[name='notebook']");
                                for(var i=0; i<notebookArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(notebookAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(notebookArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'assessment') {
                                var assessment = record.assessment;
                                var assessmentArray = assessment.split(",");
                                var assessmentAll = $("input[name='assessment']");
                                for(var i=0; i<assessmentArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(assessmentAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(assessmentArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'printName') {
                                var printName = record.printName;
                                var printNameArray = printName.split(",");
                                var printNameAll = $("input[name='printName']");
                                for(var i=0; i<printNameArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(printNameAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(printNameArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'wechat') {
                                var wechat = record.wechat;
                                var wechatArray = wechat.split(",");
                                var wechatAll = $("input[name='wechat']");
                                for(var i=0; i<wechatArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(wechatAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(wechatArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else if (key == 'admissionNotice') {
                                var admissionNotice = record.admissionNotice;
                                var admissionNoticeArray = admissionNotice.split(",");
                                var admissionNoticeAll = $("input[name='admissionNotice']");
                                for(var i=0; i<admissionNoticeArray.length; i++){
                                    //获取所有复选框对象的value属性，然后，symptomArray[i]和他们匹配，如果有，则说明他应被选中
                                    $.each(admissionNoticeAll,function(j,checkbox){
                                        //获取复选框的value属性
                                        var checkValue = $(checkbox).val();
                                        if(admissionNoticeArray[i] == checkValue){
                                            $(checkbox).attr("checked",true);
                                            // $(checkbox).next().addClass('layui-form-checked');
                                        }
                                    });
                                }
                            } else {
                                $("[name='" + key + "']").val(record[key]);
                            }
						}
                        layui.form.render();
					}
				});
			</#if>
            $(".ajax-form").unbind().submit(function () {
                try {
                    var form = $(this);
                    if (!form.valid()) {
                        $.message("验证不通过，无法提交表单");
                        return false;
                    }

                    form.formSubmit({
                        callBack:function (data) {
                            <#if (params.tag)??>
                            history.go(-1);
                            </#if>
                        }
                    });
                } catch (e) {
                    console.log("表单提交错误：" + e);
                }
                return false;
            });
		});
	</script>
    <style>
        .layui-form select {display:none !important;}
    </style>
</head>
<body>
	<div class="ui-form">
		<form class="layui-form ajax-form" action="${params.contextPath}/web/newElderPreparation/<#if (params.id)??>modify<#else>save</#if>.json" method="post">
			<input type="hidden" name="id" value="${params.id}" />
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <#if (params.tag)??>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">老人<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="hidden" name="elderId" id="elderId" value=""/>
                                        <input type="text" id="elderName" name="elderName" class="layui-input" autocomplete="off"/>
                                    </div>
                                </div>
                            <#else>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">老人<span class="ui-request">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="hidden" name="elderId"/>
                                        <input type="text" name="elderName" placeholder="请选择老人" p="model:'elder',handlerId:'elder_handler_select'" class="layui-input single-model-select {required:true}" readonly>
                                    </div>
                                </div>
                            </#if>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                            <label class="layui-form-label">物品准备<span class="ui-request">*</span></label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="itemPreparation" value="浴凳" title="浴凳">
                                <input type="checkbox" name="itemPreparation" value="防滑垫" title="防滑垫">
                                <input type="checkbox" name="itemPreparation" value="椅子" title="椅子">
                                <input type="checkbox" name="itemPreparation" value="空调遥控器" title="空调遥控器">
                                <input type="checkbox" name="itemPreparation" value="电视遥控器" title="电视遥控器">
                                <input type="checkbox" name="itemPreparation" value="床上三件套" title="床上三件套">
                                <input type="checkbox" name="itemPreparation" value="钥匙" title="钥匙">
                                <input type="checkbox" name="itemPreparation" value="垃圾桶" title="垃圾桶">
                                <input type="checkbox" name="itemPreparation" value="马桶刷" title="马桶刷">
                                <input type="checkbox" name="itemPreparation" value="呼叫器" title="呼叫器">
                                <input type="checkbox" name="itemPreparation" value="灭蚊器" title="灭蚊器">
                                <input type="checkbox" name="itemPreparation" value="护理员服务记录表" title="护理员服务记录表">
                            </div>
                        </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">检查卫生<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="checkHygiene" value="门窗" title="门窗">
                                    <input type="checkbox" name="checkHygiene" value="桌面" title="桌面">
                                    <input type="checkbox" name="checkHygiene" value="地面" title="地面">
                                    <input type="checkbox" name="checkHygiene" value="踢脚线" title="踢脚线">
                                    <input type="checkbox" name="checkHygiene" value="电器" title="电器">
                                    <input type="checkbox" name="checkHygiene" value="柜子" title="柜子">
                                    <input type="checkbox" name="checkHygiene" value="开关" title="开关">
                                    <input type="checkbox" name="checkHygiene" value="衣物摆放" title="衣物摆放">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md8">
                            <div class="layui-form-item">
                                <label class="layui-form-label">记录本<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="notebook" value="床上三件套" title="床上三件套">
                                    <input type="checkbox" name="notebook" value="钥匙" title="钥匙">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-form-item">
                                <label class="layui-form-label">电表度数<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="text" name="powerMeter" placeholder="请输入电表度数" class="layui-input"/>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">评估<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="assessment" value="生活习惯" title="生活习惯"/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">打名字<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="printName" value="餐厅座位" title="餐厅座位"/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">加微信<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="wechat" value="加微信" title="加微信"/>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-form-item">
                                <label class="layui-form-label">入院须知<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="admissionNotice" value="长者或家属签字" title="长者或家属签字"/>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row">
                        <div class="layui-col-md12">
                            <div class="layui-form-item">
                                <label class="layui-form-label">其他特殊情况</label>
                                <div class="layui-input-block">
                                    <textarea name="otherSpecialCircumstances" placeholder="请输入其他特殊情况" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="submit" value="保存" class="layui-btn" />
				</div>
			</div>
		</form>
	</div>
</body>
<script src="${params.contextPath}/static/plug/layui/layui.all.js"></script>

</html>
